package cn.wolfcode.p2p.business.controller;

import cn.wolfcode.p2p.anno.NeedLogin;
import cn.wolfcode.p2p.base.query.RechargeOfflineQueryObject;
import cn.wolfcode.p2p.business.domain.RechargeOffline;
import cn.wolfcode.p2p.business.service.IPlatformBankInfoService;
import cn.wolfcode.p2p.business.service.IRechargeOfflineService;
import cn.wolfcode.p2p.util.JSONResultUtil;
import cn.wolfcode.p2p.util.Order;
import cn.wolfcode.p2p.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 充值
 */
@Controller
public class RechargeController {

    @Autowired
    private IPlatformBankInfoService platformBankInfoService;
    @Autowired
    private IRechargeOfflineService rechargeOfflineService;

    /**
     * 充值页面
     * @return
     */
    @NeedLogin
    @RequestMapping("recharge")
    public String rechargePage(Model model){
        model.addAttribute("banks",platformBankInfoService.listPlatformBankInfo());
        return "recharge";
    }

    /**
     * 充值
     */
    @NeedLogin
    @RequestMapping("recharge_save")
    @ResponseBody
    public Object rechargeOffline(RechargeOffline rechargeOffline){
        rechargeOfflineService.rechargeOffline(rechargeOffline);
        return JSONResultUtil.jsonResult();
    }

    /**
     * 充值明细
     */
    @NeedLogin
    @RequestMapping("recharge_list")
    public String rechargelist(@ModelAttribute("qo")RechargeOfflineQueryObject qo,Model model){
        qo.setApplierId(UserContext.getLoginInfo().getId());
        qo.setOrderBy(Order.ORDERBY_COLUMN_APPLY_TIME.orderBy);
        model.addAttribute("pageResult",rechargeOfflineService.queryRechargeList(qo));
        return "recharge_list";
    }
}
